<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>管理员登录</title>

    <!--引入bootstrap-->
    <th:block th:insert="~{/fixed/header::head}"></th:block>
    <!--登录界面样式-->
    <link rel="stylesheet" th:href="@{/css/login.css}">
</head>
<script>
    $(function (){

        //监听回车事件，触发登录
        $("*").bind("keydown",function (e){
            //兼容浏览器的事件
            let theEvent = e || window.event;
            //兼容各浏览器的键盘事件
            let keyCode = theEvent.keyCode || theEvent.which || theEvent.charCode;
            if (keyCode == 13){
                $("#login").click();
            }
        })

        $("#login").click(function (){
            //获取页面数据
            let inputUserName = $("#inputUserName").val();
            let inputPassword = $("#inputPassword").val();
            //判定是否有空值
            if (inputUserName != "" && inputPassword != ""){
                $.ajax({
                    url:"/admin/checkLogin",
                    method:"POST",
                    data:{"adminLoginName":inputUserName,"adminPassword":inputPassword},
                    success:function (data){
                        if (data){
                            location.href = "/admin/index";
                        }else {
                            $("#modalText").text("用户名或密码错误");
                            $("#myModal").modal('show');
                        }
                    }
                })
            }else {
                $("#modalText").text("用户名或密码不能为空");
                $("#myModal").modal('show');
            }
        })
    })
</script>
<body class="text-center">
<form class="form-signin" novalidate>
    <img class="mb-4" th:src="@{/img/CHLogo.png}" alt="" width="72" height="72">
    <h1 class="h3 mb-3 font-weight-normal">管理员登录</h1>
    <label for="inputUserName" class="sr-only">登录名</label>
    <input type="text" id="inputUserName" class="form-control" placeholder="请输入用户名">
    <label for="inputPassword" class="sr-only">密码</label>
    <input type="password" id="inputPassword" class="form-control" placeholder="请输入密码">
    <div class="checkbox mb-3">
        <label>
            <input type="checkbox" value="remember-me"> 记住我
        </label>
    </div>
    <button class="btn btn-lg btn-primary btn-block" type="button" id="login">登录</button>
    <p class="mt-5 mb-3 text-muted">© 2021-2021</p>
</form>
<!--引入模态框-->
<th:block th:insert="~{/fixed/modal::modal}"></th:block>
</body>
</html>